package com.ly.lw.styledo.fragment;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RadioGroup;

import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.ly.lw.styledo.R;
import com.ly.lw.styledo.adapter.BrandFmPageAdapter;

import java.util.ArrayList;


public class BrandFragment extends Fragment implements RadioGroup.OnCheckedChangeListener {
    @ViewInject(R.id.fragment_brand_viewpager)
    private ViewPager brandViewpager;
    @ViewInject(R.id.brand_rgs)
    private RadioGroup rgs;
    private BrandFmPageAdapter brandFmPageAdapter;
    ArrayList<Fragment> fragments = new ArrayList<>();


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);


    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_brand, container, false);
        ViewUtils.inject(this, view);
        initView();

        return view;
    }

    private void initView() {
        //数据源
        loadData();
        brandFmPageAdapter = new BrandFmPageAdapter(getChildFragmentManager(), fragments);
        brandViewpager.setAdapter(brandFmPageAdapter);
        rgs.setOnCheckedChangeListener(this);


    }

    private void loadData() {
        fragments.add(new BrandAllFragment());
        fragments.add(new BrandBaseFragment());

    }


    @Override
    public void onCheckedChanged(RadioGroup group, int checkedId) {
        switch (checkedId) {
            case R.id.brand_all_rb:
                brandViewpager.setCurrentItem(0);


                break;
            case R.id.brand_women_rb:
                brandViewpager.setCurrentItem(1);

                break;
        }

    }
}
